/* Для каждого федерального округа выдать количество разных часовых поясов,
в которых расположены его подразделения. */

select
  max(adm_units.name) as federal_district,
  count (distinct time_zone) as time_zones_count
from
  (
    select
      connect_by_root adm_units.id as federal_district_id,
      adm_units_time_zones.time_zone
  
    from
      adm_units
      left join adm_units_types on adm_units.type = adm_units_types.id
      left join adm_units_time_zones on adm_units.id = adm_units_time_zones.adm_unit
  
    start with adm_units_types.type = 'Федеральный округ'
    connect by prior adm_units.id = adm_units.parent_unit
  ) federal_with_children
  left join adm_units on federal_with_children.federal_district_id = adm_units.id
  
group by federal_with_children.federal_district_id;